package com.e3.web.core.client;

import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.user.client.rpc.AsyncCallback;

public abstract class GwtAsyncCallback<T> implements AsyncCallback<T>{
	
	private Component maskComponent;
		
//	public GwtAsyncCallback() {
//	}
	
	public GwtAsyncCallback(Component maskComponent) {
		this.maskComponent = maskComponent;
	}

	public void onFailure(Throwable caught) {
		caught.printStackTrace();
		doFailure(caught);
	}

	public void onSuccess(T result) {
		GXTHelper.unmask(maskComponent);
		doSuccess(result);
	}
	
	public void doFailure(Throwable caught){
		GXTHelper.unmask(maskComponent);
		MessageBox.alert("错误", caught.getMessage(), null);
	}

	public abstract void doSuccess(T result);
	
	public Component getMaskOwnerComponent(){
		return maskComponent;
	}
//
//	private void unmask(){
//		if(getMaskOwnerComponent()!=null){
//			getMaskOwnerComponent().unmask();
//		}
//	}
}
